//== GAIA ============================================================================

//== BEGINNING OF CODE ===============================================================

//#include "sagittarius/core/SagittariusCore.h"


#include <stdio.h>
#include <malloc.h>
#include <assert.h>
#include <math.h>
#include "sagittarius/parallel/atomics.h"
#include "sagittarius/parallel/wrfutex.h"

#include <unistd.h>
//#include <time.h>
#include <sys/time.h>
#include <sys/syscall.h>
//#include <sched.h>
#include <errno.h>
//#include <fcntl.h>
//#include <signal.h>

long create_thread(void (*thread_func)(void*), void* param);
void exit_thread(long result);

void target(void* arg) {
    sg_write(2, "target was run\n", sizeof("target was run\n"));
    exit_thread(0);
    //return 0;
}

struct timespec t = {10, 0};

int main(int argc, char* argv[])
{
    long res=0;
    create_thread(target, NULL);
    if(res < 0)
        perror("Error creating process");
    //sleep for 10sec
    syscall(SYS_nanosleep, &t, NULL);
    sg_write(2, "sleep finished\n", sizeof("sleep finished\n"));
    
    return 0;
}
